const { createOrUpdate } = require('../service/carts_service')

class Cartcontroller {
    //将商品添加到购物车
    async add(ctx) {
        //1.解析userid
        const user_id = ctx.state.user.id
        //goods_id
        const { goods_id } = ctx.request.body
        // console.log(id, goods_id);

        //2.操作数据库
        const res = await Goods.createOrUpdate(user_id, goods_id)

        // 3.返回结果
        ctx.body = {
            code: 0,
            message: "添加购物车成功",
            result: res
        }

    }
}

module.exports = new Cartcontroller();